﻿using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using TESTCommons.JsonHelper;
using TestModel.SysManage;
using TestService.SysManage;

namespace TestManage.Areas.Api
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class SysLogController : Controller
    {
        #region 参数
        private readonly ISys_LogService _logService;
        #endregion

        #region 构造函数
        public SysLogController(ISys_LogService logService)
        {
            _logService = logService;
        }
        #endregion

        /// <summary>
        /// 添加日志
        /// </summary>

        [HttpPost]
        public IActionResult AddLog(sys_Log model)
        {
            _logService.AddLog(model);
            return Json(new AjaxResult { type = ResultType.success, message = "添加日志成功" });
        }

        // GET: api/<controller>
        [HttpGet]
        [EnableCors("_myAllowSpecificOrigins")]
        public IEnumerable<string> Get()
        {
            return new string[] { "value1", "value2" };
        }

        // GET api/<controller>/5
        [HttpGet]//("{id}")
        //[EnableCors("_myAllowSpecificOrigins")]
        public string Getid(int id)
        {
            //return $"value:{id}";
            switch (id)
            {
                case 1:
                    return "green widget";
                case 2:
                    return "red widget";
                default:
                    return "NotFound";
            }
        }

        // POST api/<controller>
        [HttpPost]
        public void Post([FromBody]string value)
        {
        }

        // PUT api/<controller>/5
        [HttpPut("{id}")]
        public void Put(int id, [FromBody]string value)
        {
        }

        // DELETE api/<controller>/5
        [HttpDelete("{id}")]
        public void Delete(int id)
        {
        }
    }
}
